<template>
  <div>
    <a-card :bordered="false">
      <f-search-form @searchHandler="searchHandler">
        <f-search-form-item label="姓名" name="userName"/>
        <f-search-form-item label="昵称" name="nickName"/>
        <f-search-form-item label="用户状态" name="status" type="select" :data="api.common.userStatus"></f-search-form-item>
        <f-search-form-item label="手机号" name="mobile" slot="advanced"/>
        <f-search-form-item label="生日日期" name="birthday" type="date" slot="advanced"/>
        <f-search-form-item label="注册日期" name="rangeDate" type="range" slot="advanced"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="userId" :columns="columns" :scroll="{ x: 1600 }" :operator="operator" :params="queryParam" :api="api.frontUser" order="createTime">
        <span slot="status" slot-scope="text, record, index">
          <a-switch v-model="record.status==1" checkedChildren="启用" unCheckedChildren="禁用" @change="setStatus(record)"/>
        </span>
        <span slot="avatar" slot-scope="text">
           <f-images :value="text"></f-images>
        </span>
        <span slot="sexSlot" slot-scope="text">
          <a-tag>{{dictFormat('sex',text,'未知')}}</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.userId)">删除</a>
              </a-menu-item>
               <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.account.handleShow(record)">账户管理</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </f-table>
      <!-- <div class="ant-table-content" >
         <tbody class="ant-table-tbody" style="width:100%">
         <tr class="ant-table-row">
           <td class="ant-table-column" > 合计:</td>
           <td class="ant-table-column">金额:13000000003</td>
         </tr>
         </tbody>
       </div>-->
    </a-card>
    <user-modal ref="modal"></user-modal>
    <user-account ref="account"></user-account>
  </div>
</template>

<script>
  import UserModal from './user_modal'
  import UserAccount from './account/index'

  export default {
    name: 'TableList',
    components: {
      UserAccount,
      UserModal
    },
    data() {
      return {
        tableId: 'appUser',
        //列表初始化查询参数
        queryParam: { userType: 'USER' },
        // 表头
        columns: [
          {
            title: '#',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },

          {
            title: '头像',
            align: 'center',
            dataIndex: 'avatar',
            scopedSlots: { customRender: 'avatar' }
          },
          {
            title: '姓名',
            align: 'center',
            width: 90,
            dataIndex: 'userName'
          }, {
            title: 'ID',
            align: 'center',
            dataIndex: 'userNo'
          },
          {
            title: '昵称',
            align: 'center',
            dataIndex: 'nickName'
          },
          {
            title: '性别',
            align: 'center',
            dataIndex: 'sex',
            scopedSlots: { customRender: 'sexSlot' }
          },
          {
            title: '城市',
            align: 'center',
            width: 190,
            dataIndex: 'areaName'
          },
          {
            title: '邮箱',
            align: 'center',
            dataIndex: 'email',
            sorter: true,
            width: 150,
            customRender: (text) => text
          },
          {
            title: '生日',
            align: 'center',
            dataIndex: 'birthday'
          },
          {
            title: '手机号',
            align: 'center',
            dataIndex: 'mobile'
          },
          {
            title: '邀请码',
            align: 'center',
            dataIndex: 'shareCode'
          },

          {
            title: '注册日期',
            align: 'center',
            dataIndex: 'createTime',
            width: 190,
            sorter: true
          },
          {
            title: '状态',
            align: 'center',
            dataIndex: 'status',
            fixed: 'right',
            sorter: true,
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '操作',
            align: 'center',
            fixed: 'right',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          //   {
          //     name: '添加用户',
          //     icon: 'plus',
          //     that: this,
          //     handler: function(table, that) {
          //       that.$refs.modal.handleShow()
          //     }
          //   },
          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    created() {

    },
    methods: {
      setStatus(record) {
        this.http.post(this, {
          url: this.api.frontUser.setStatus,
          data: {
            userId: record.userId
          },
          success(me, data) {
            record.status = data
          }
        })
      }
    }
  }
</script>
